import java.util.Scanner;

public class _01背包优化一维 {
    static int N = 1010;
    static int[] f = new int[N];
    static int[] v = new int[N];
    static int[] w = new int[N];
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        for(int i=1;i<=n;i++) {
            v[i] = s.nextInt();
            w[i] = s.nextInt();
        }
        System.out.print("   ");
        for (int i = 0; i <=m; i++) System.out.print(i+"  ");
        System.out.println();

        for(int i = 1; i <= n; i++) {
            System.out.print(i+":  ");
            for (int j = 0; j <= m; j++) {
                // 优化前f[i][j] = f[i - 1][j];
                //f[j] = f[j];     优化后，该行自动成立，可省略。
                // 优化前f[i][j] = max(f[i - 1][j], f[i - 1][j - v[i]] + w[i]);
                if (j >= v[i])
                    f[j] = Math.max(f[j], f[j - v[i]] + w[i]);
                System.out.print(f[j] + "  ");
            }
            System.out.println();
        }
        System.out.println(f[m]);
    }
}
